Skip to content

Commit 8a2229c

Browse files
authored
Add tests for Source Phase Imports (#3980)
1 parent c3a326a commit 8a2229c

File tree

284 files changed

+10329
-26
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+10329
-26
lines changed

INTERPRETING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ properties of the global scope prior to test execution.
107107
- **`sleep`** - a function that takes a millisecond argument and
108108
sleeps the execution for approximately that duration.
109109
- **`monotonicNow`** - a function that returns a value that conforms to [`DOMHighResTimeStamp`][] and is produced in such a way that its semantics conform to **[Monotonic Clock][]**.
110+
- **`AbstractModuleSource`** - a reference to the `%AbstractModuleSource%` constructor which does not appear as a property of the global object.
110111

111112
In addition, consumers may choose to override any of [the functions defined by test harness files](https://github.com/tc39/test262/blob/HEAD/CONTRIBUTING.md#test-environment) as they see fit. See [the documentation on handling errors and negative test cases](https://github.com/tc39/test262/blob/HEAD/CONTRIBUTING.md#handling-errors-and-negative-test-cases) for a useful example of this.
112113

@@ -160,6 +161,12 @@ located at `test/language/import/nested/dep.js`.
160161

161162
Files bearing a name ending in `.json` are intended to be interpreted as JSON.
162163

164+
Implementers should resolve the specifier `<module source>` to a module that
165+
provides a valid [Module Source](https://tc39.es/proposal-source-phase-imports/#sec-module-source-objects),
166+
such as a [WebAssembly module](https://webassembly.github.io/esm-integration/js-api/index.html#webassembly-module-record).
167+
Tests use `<module source>` specifier are guarded with a feature flag
168+
`source-phase-imports-module-source`.
169+
163170
### Staging
164171

165172
Tests in the `test/staging/` folder are expected to be executed just like all the other tests, in order to promote interoperability as soon as possible.

features.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ explicit-resource-management
121121
# https://github.com/tc39/proposal-float16array
122122
Float16Array
123123

124+
# Source Phase Imports
125+
## https://github.com/tc39/proposal-source-phase-imports
126+
source-phase-imports
127+
## test262 special specifier
128+
source-phase-imports-module-source
129+
124130
## Standard language features
125131
#
126132
# Language features that have been included in a published version of the
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2020 Rick Waldron. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
5+
/*---
6+
esid: sec-static-semantics-static-semantics-assignmenttargettype
7+
desc: >
8+
Static Semantics AssignmentTargetType, Return invalid.
9+
info: |
10+
ImportCall
11+
Static Semantics AssignmentTargetType, Return invalid.
12+
template: invalid
13+
flags: [module]
14+
features: [source-phase-imports]
15+
negative:
16+
phase: parse
17+
type: SyntaxError
18+
---*/
19+
20+
//- assignmenttarget
21+
import.source()
22+
//- operator
23+
=
24+
//- value
25+
1
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
desc: It's a SyntaxError on unknown import call
5+
template: syntax/invalid
6+
info: |
7+
ImportCall[Yield, Await] :
8+
import ( AssignmentExpression[+In, ?Yield, ?Await] )
9+
import . source ( AssignmentExpression[+In, ?Yield, ?Await] )
10+
features: [source-phase-imports]
11+
---*/
12+
//- import
13+
import.UNKNOWN('./empty_FIXTURE.js')
14+
//- teardown
15+
/* The params region intentionally empty */
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2018 Rick Waldron. All rights reserved.
3+
// Copyright (C) 2018 the V8 project authors. All rights reserved.
4+
// This code is governed by the BSD license found in the LICENSE file.
5+
/*---
6+
desc: It's a SyntaxError if AssignmentExpression is omitted
7+
template: syntax/invalid
8+
info: |
9+
ImportCall[Yield, Await] :
10+
import . source ( AssignmentExpression[+In, ?Yield, ?Await] )
11+
features: [source-phase-imports]
12+
---*/
13+
//- import
14+
import.source()
15+
//- teardown
16+
/* The params region intentionally empty */
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2018 Rick Waldron. All rights reserved.
3+
// Copyright (C) 2018 the V8 project authors. All rights reserved.
4+
// This code is governed by the BSD license found in the LICENSE file.
5+
/*---
6+
desc: Calling import.source('')
7+
template: syntax/valid
8+
features: [source-phase-imports, source-phase-imports-module-source]
9+
---*/
10+
11+
//- import
12+
import.source('<module source>')
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2018 Leo Balter. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
desc: ImportCall is a CallExpression, it can't be preceded by the new keyword
6+
template: syntax/invalid
7+
info: |
8+
CallExpression:
9+
ImportCall
10+
11+
ImportCall :
12+
import . source ( AssignmentExpression[+In, ?Yield, ?Await] )
13+
14+
features: [source-phase-imports, source-phase-imports-module-source]
15+
---*/
16+
17+
//- import
18+
new import.source('<module source>')
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2018 Leo Balter. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
desc: ImportCall is not extensible - no rest parameter
6+
template: syntax/invalid
7+
info: |
8+
ImportCall :
9+
import . source ( AssignmentExpression[+In, ?Yield] )
10+
11+
Forbidden Extensions
12+
13+
- ImportCall must not be extended.
14+
15+
This production doesn't allow the following production from ArgumentsList:
16+
17+
... AssignmentExpression
18+
features: [source-phase-imports, source-phase-imports-module-source]
19+
---*/
20+
21+
//- import
22+
import.source(...['<module source>'])
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2018 Leo Balter. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
desc: import.source() can be used in script code
6+
template: syntax/valid
7+
features: [source-phase-imports, source-phase-imports-module-source]
8+
---*/
9+
10+
//- setup
11+
// This is still valid in script code, and should not be valid for module code
12+
// https://tc39.github.io/ecma262/#sec-scripts-static-semantics-lexicallydeclarednames
13+
var smoosh; function smoosh() {}
14+
15+
//- import
16+
import.source('<module source>')
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
desc: >
5+
GetModuleSource of SourceTextModule always returns an abrupt completion.
6+
esid: sec-moduleevaluation
7+
info: |
8+
16.2.1.7.2 GetModuleSource ( )
9+
Source Text Module Record provides a GetModuleSource implementation that always returns an abrupt completion indicating that a source phase import is not available.
10+
1. Throw a ReferenceError exception.
11+
12+
Import Calls
13+
14+
Runtime Semantics: Evaluation
15+
16+
ImportCall : import . source ( AssignmentExpression )
17+
1. Return ? EvaluateImportCall(AssignmentExpression, source).
18+
19+
13.3.10.1.1 EvaluateImportCall ( specifierExpression, phase )
20+
1. Let referrer be GetActiveScriptOrModule().
21+
2. If referrer is null, set referrer to the current Realm Record.
22+
3. Let specifierRef be ? Evaluation of specifierExpression.
23+
4. Let specifier be ? GetValue(specifierRef).
24+
5. Let promiseCapability be ! NewPromiseCapability(%Promise%).
25+
6. Let specifierString be Completion(ToString(specifier)).
26+
7. IfAbruptRejectPromise(specifierString, promiseCapability).
27+
8. Let moduleRequest be a new ModuleRequest Record { [[Specifier]]: specifierString, [[Phase]]: phase }.
28+
9. Perform HostLoadImportedModule(referrer, moduleRequest, empty, promiseCapability).
29+
10. Return promiseCapability.[[Promise]].
30+
31+
template: catch
32+
features: [source-phase-imports]
33+
---*/
34+
35+
//- import
36+
import.source('./empty_FIXTURE.js')
37+
//- body
38+
assert.sameValue(error.name, 'ReferenceError');
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2018 Rick Waldron. All rights reserved.
3+
// Copyright (C) 2018 the V8 project authors. All rights reserved.
4+
// This code is governed by the BSD license found in the LICENSE file.
5+
/*---
6+
desc: >
7+
Abrupt from ToString(specifier) rejects the promise
8+
esid: sec-moduleevaluation
9+
info: |
10+
Import Calls
11+
12+
Runtime Semantics: Evaluation
13+
14+
ImportCall : import . source ( AssignmentExpression )
15+
1. Return ? EvaluateImportCall(AssignmentExpression, source).
16+
17+
13.3.10.1.1 EvaluateImportCall ( specifierExpression, phase )
18+
1. Let referrer be GetActiveScriptOrModule().
19+
2. If referrer is null, set referrer to the current Realm Record.
20+
3. Let specifierRef be ? Evaluation of specifierExpression.
21+
4. Let specifier be ? GetValue(specifierRef).
22+
5. Let promiseCapability be ! NewPromiseCapability(%Promise%).
23+
6. Let specifierString be Completion(ToString(specifier)).
24+
7. IfAbruptRejectPromise(specifierString, promiseCapability).
25+
8. Let moduleRequest be a new ModuleRequest Record { [[Specifier]]: specifierString, [[Phase]]: phase }.
26+
9. Perform HostLoadImportedModule(referrer, moduleRequest, empty, promiseCapability).
27+
10. Return promiseCapability.[[Promise]].
28+
template: catch
29+
features: [source-phase-imports]
30+
---*/
31+
32+
//- setup
33+
const obj = {
34+
toString() {
35+
throw 'custom error';
36+
}
37+
};
38+
39+
//- import
40+
import.source(obj)
41+
//- body
42+
assert.sameValue(error, 'custom error');
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2018 Rick Waldron. All rights reserved.
3+
// Copyright (C) 2018 the V8 project authors. All rights reserved.
4+
// This code is governed by the BSD license found in the LICENSE file.
5+
/*---
6+
desc: >
7+
ToString value of specifier
8+
esid: sec-moduleevaluation
9+
info: |
10+
Import Calls
11+
12+
Runtime Semantics: Evaluation
13+
14+
ImportCall : import . source ( AssignmentExpression )
15+
1. Return ? EvaluateImportCall(AssignmentExpression, source).
16+
17+
13.3.10.1.1 EvaluateImportCall ( specifierExpression, phase )
18+
1. Let referrer be GetActiveScriptOrModule().
19+
2. If referrer is null, set referrer to the current Realm Record.
20+
3. Let specifierRef be ? Evaluation of specifierExpression.
21+
4. Let specifier be ? GetValue(specifierRef).
22+
5. Let promiseCapability be ! NewPromiseCapability(%Promise%).
23+
6. Let specifierString be Completion(ToString(specifier)).
24+
7. IfAbruptRejectPromise(specifierString, promiseCapability).
25+
8. Let moduleRequest be a new ModuleRequest Record { [[Specifier]]: specifierString, [[Phase]]: phase }.
26+
9. Perform HostLoadImportedModule(referrer, moduleRequest, empty, promiseCapability).
27+
10. Return promiseCapability.[[Promise]].
28+
29+
16.2.1.7.2 GetModuleSource ( )
30+
Source Text Module Record provides a GetModuleSource implementation that always returns an abrupt completion indicating that a source phase import is not available.
31+
1. Throw a ReferenceError exception.
32+
33+
template: catch
34+
features: [source-phase-imports]
35+
---*/
36+
37+
//- setup
38+
// The following case is equivalent of the call of:
39+
// import.source('./empty_FIXTURE.js')
40+
41+
const obj = {
42+
toString() {
43+
return './empty_FIXTURE.js';
44+
}
45+
};
46+
47+
//- import
48+
import.source(obj)
49+
//- body
50+
assert.sameValue(error.name, 'ReferenceError');
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
desc: It's a SyntaxError on unexpected import source property
5+
template: syntax/invalid
6+
info: |
7+
ImportCall[Yield, Await] :
8+
import ( AssignmentExpression[+In, ?Yield, ?Await] )
9+
import . source ( AssignmentExpression[+In, ?Yield, ?Await] )
10+
features: [source-phase-imports]
11+
---*/
12+
//- import
13+
typeof import.source.UNKNOWN
14+
//- teardown
15+
/* The params region intentionally empty */
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
desc: It's a SyntaxError if '()' is omitted
5+
template: syntax/invalid
6+
info: |
7+
ImportCall[Yield, Await] :
8+
import . source ( AssignmentExpression[+In, ?Yield, ?Await] )
9+
features: [source-phase-imports]
10+
---*/
11+
//- import
12+
typeof import.source
13+
//- teardown
14+
/* The params region intentionally empty */

src/dynamic-import/typeof-import.case

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
desc: It's a SyntaxError if '()' is omitted
5+
template: syntax/invalid
6+
info: |
7+
ImportCall[Yield, Await] :
8+
import . source ( AssignmentExpression[+In, ?Yield, ?Await] )
9+
---*/
10+
//- import
11+
typeof import
12+
//- teardown
13+
/* The params region intentionally empty */
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
esid: sec-properties-of-the-%abstractmodulesource%25-intrinsic-object
5+
description: >
6+
%AbstractModuleSource%.length property descriptor
7+
info: |
8+
28.1.1.1 %AbstractModuleSource% ( )
9+
10+
includes: [propertyHelper.js]
11+
features: [source-phase-imports]
12+
flags: [module]
13+
---*/
14+
15+
assert.sameValue(typeof $262.AbstractModuleSource, 'function');
16+
verifyProperty($262.AbstractModuleSource, 'length', {
17+
value: 0,
18+
writable: false,
19+
enumerable: false,
20+
configurable: true
21+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
esid: sec-properties-of-the-%abstractmodulesource%25-intrinsic-object
5+
description: >
6+
%AbstractModuleSource%.name property descriptor
7+
info: |
8+
The %AbstractModuleSource% intrinsic object has a "name" property whose value is "AbstractModuleSource".
9+
10+
Unless otherwise specified, the name property of a built-in function
11+
object, if it exists, has the attributes { [[Writable]]: false,
12+
[[Enumerable]]: false, [[Configurable]]: true }.
13+
includes: [propertyHelper.js]
14+
features: [source-phase-imports]
15+
flags: [module]
16+
---*/
17+
18+
assert.sameValue(typeof $262.AbstractModuleSource, 'function');
19+
verifyProperty($262.AbstractModuleSource, 'name', {
20+
value: 'AbstractModuleSource',
21+
writable: false,
22+
enumerable: false,
23+
configurable: true
24+
});

0 commit comments

Comments
 (0)